<template>
  <div class="form-container">
    <div class="top">
      <el-form size="mini" ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item v-if="hasDeal" prop="isDeal" label="是否成交">
          <el-checkbox v-model="form.isDeal">已成交（请将成交信息填入备注）</el-checkbox>
        </el-form-item>
        <el-form-item v-if="hasDeal && form.isDeal" prop="customerId" label="成交客户">
          <el-select v-model="form.customerId" placeholder="请选择">
            <el-option v-for="item in customerList" :key="item.id" :label="item.com_name" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="msg" label="备注">
          <el-input v-model="form.msg" placeholder="请填写回访内容及结论" type="textarea" :rows="5" />
        </el-form-item>
      </el-form>
    </div>
    <div class="bottom">
      <div class="line">
        <el-button size="mini" type="primary" @click="onSubmit">提交</el-button>
      </div>
    </div>
  </div>
</template>
<script>
import { apiPushLeftContactAdd } from '@/api/assetsDisposal'

export default {
  props: {
    id: String,
    hasDeal: Boolean,
    customerList: {
      type: Array,
      default: () => {
        return []
      },
    },
  },
  data() {
    return {
      form: {
        isDeal: false,
        customerId: '',
        msg: '',
      },
      rules: {
        isDeal: [{ required: true, message: '请选择', trigger: 'blur' }],
        customerId: [{ required: true, message: '请选择成交客户', trigger: 'blur' }],
        msg: [{ required: true, message: '请填写回访内容及结论', trigger: 'blur' }],
      },
    }
  },
  watch: {},
  computed: {},
  mounted() {},
  methods: {
    // 提交
    onSubmit() {
      this.$refs.form.validate((flag) => {
        if (flag) {
          let form = {}
          if (this.hasDeal && this.form.isDeal) {
            form = {
              id: this.form.customerId,
              is_deal: this.form.isDeal ? 1 : 0,
              msg: this.form.msg,
            }
          } else {
            form = {
              id: this.id,
              msg: this.form.msg,
            }
          }
          const formData = new FormData()
          for (let key in form) {
            formData.set(key, form[key])
          }
          apiPushLeftContactAdd(formData).then((res) => {
            if (res.code === 200) {
              this.$emit('confirm')
            }
          })
        }
      })
    },
    // 删除
    onDelete() {
      const form = {
        id: this.id,
        send_to_feijiu: 1,
      }
      const formData = new FormData()
      for (let key in form) {
        formData.set(key, form[key])
      }
      apiVipCateDel(formData).then((res) => {
        if (res.code === 200) {
          this.$emit('delete', this.id)
        }
      })
    },
  },
}
</script>
<style lang="scss" scoped>
.form-container {
  padding: 0 24px;
  .top {
    min-height: 300px;
  }
  .bottom {
    .line {
      display: flex;
      justify-content: flex-end;
    }
  }
  .el-cascader {
    width: 100%;
    .el-input {
      width: 100% !important;
      margin: 0 !important;
    }
  }
  .el-input {
    width: 150px !important;
    margin: 0 5px !important;
  }
  .line {
    display: inline-block;
    margin-left: 10px;
  }
}
</style>

<style>
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none !important;
  margin: 0;
}
</style>
